package com.llh.pojo.common;

import com.llh.pojo.trade.responseBean.common.RespParams;
import lombok.Data;

import java.lang.reflect.Field;

/**
 * 处理请求头fileds参数的工具类
 */
@Data
public class CommonFiledTool {
    //请求参数:"exchange,cal_date,is_open,pretrade_date"
    public String fields = "";
    /*响应参数: [
                            "exchange",
                            "cal_date",
                            "is_open",
                            "pretrade_date"
                    ]*/
    public RespParams respFields;

    public boolean init(){
        try{
            StringBuilder stringBuilder = new StringBuilder();
            Field[] fields = respFields.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                String name = field.getName();
                Boolean b = (Boolean)field.get(respFields);
                if(b!=null&&b.equals(true)){
                    stringBuilder.append(name+",");
                }
            }
            String s = stringBuilder.toString();
            this.fields = s.substring(0,s.length()-1);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }
}
